-
-
Notifications
You must be signed in to change notification settings - Fork 320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add example for raw API Server requests #1330
Conversation
I noticed a couple of questions around querying the metrics API that a kubelet exposes. A number of different use cases aside from stat queries may require raw requests to the API Server (in the style of `kubectl get --raw`). It does not make much sense to extend the Request API to cover this use case (since an abstraction would not simplify anything). Users can, however, make use of the `http::Request` type and use an instantiated client to interface with the API Server. There's a lack of material here, so I thought I'd include an example that other people may reference. The example builds the equivalent of `kubectl top nodes` (in a simpler, and dumber way) using raw HTTP requests. The data may not be as exact as what `kubectl top` offers, but it serves as an example on how data may be queried. Signed-off-by: Matei David <[email protected]>
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #1330 +/- ##
=======================================
- Coverage 72.4% 72.1% -0.2%
=======================================
Files 75 75
Lines 6343 6377 +34
=======================================
+ Hits 4586 4597 +11
- Misses 1757 1780 +23 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for this, saw you were providing helpful answers.
i like this example, it's advanced enough to be useful, and not too complicated either.
there are a few nits i've suggested to make it more readable, but this is definitely parseable.
* Remove redundant `.items` acess. * Rename NodeMetric to NodeMetrics * std::cmp instead of manually comparing. Co-authored-by: Eirik A <[email protected]> Signed-off-by: Matei David <[email protected]>
Signed-off-by: Matei David <[email protected]>
…nto matei/add-raw-example
Signed-off-by: Matei David <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot!
Motivation
I noticed a couple of questions around querying the metrics API that a kubelet exposes. A number of different use cases aside from stat queries may require raw requests to the API Server (in the style of
kubectl get --raw
).It does not make much sense to extend the Request API to cover this use case (since an abstraction would not simplify anything). Users can, however, make use of the
http::Request
type and use an instantiated client to interface with the API Server. There's a lack of material here, so I thought I'd include an example that other people may reference.Solution
The example builds the equivalent of
kubectl top nodes
(in a simpler, and dumber way) using raw HTTP requests. The data may not be as exact as whatkubectl top
offers, but it serves as an example on how data may be queried.If this isn't needed, I'm happy to put it in a gist somewhere, no time wasted so no worries there :) It is an unsolicited PR.